package com.mm.update.service;

import com.mm.update.vo.DeployLog;
import org.apache.commons.collections4.queue.CircularFifoQueue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ClassName: FixedSizeQueue
 * Description:
 * date: 2025/4/21 15:49
 *
 * @author  
 * @since JDK 1.8
 */
public class FixedSizeQueue {
    private static final int MAX_SIZE = 10000;
    private static final CircularFifoQueue<DeployLog> queue = new CircularFifoQueue<>(MAX_SIZE);

    // 添加元素
    public static void addElement(DeployLog element) {
        queue.offer(element);
    }

    // 获取倒序列表（最近添加的在前）
    public static List<DeployLog> getReversedList() {
        List<DeployLog> list = new ArrayList<>(queue);
        Collections.reverse(list);
        if(list.size() > 100){
            return list.subList(0,100);

        }else{
            return list;
        }
    }
}
